# Contributor: Mika Havela <mika.havela@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=libogg
pkgver=1.3.5
pkgrel=5
pkgdesc="Ogg bitstream and framing library"
url="https://xiph.org/ogg/"
arch="all"
license="BSD-3-Clause"
makedepends="cmake samurai"
subpackages="$pkgname-doc $pkgname-static $pkgname-dev"
source="https://downloads.xiph.org/releases/ogg/libogg-$pkgver.tar.gz"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	CFLAGS="$CFLAGS -O2 -flto=auto" \
	cmake -B build-shared -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=ON \
		-DCMAKE_BUILD_TYPE=None \
		$CMAKE_CROSSOPTS
	cmake --build build-shared

	cmake -B build-static -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=OFF \
		-DCMAKE_BUILD_TYPE=Release \
		$CMAKE_CROSSOPTS
	cmake --build build-static
}

check() {
	ctest --test-dir build-shared
	ctest --test-dir build-static
}

package() {
	DESTDIR="$pkgdir" cmake --install build-static
	DESTDIR="$pkgdir" cmake --install build-shared
}

sha512sums="
e4d798621bb04a62dcb831e58a444357635ab3bcb9efbdffa009cb0be1cafb5e72bf71cbcad5305aa5268a92076a03a7e564a19c0c8d54b93a05d9b03ad2da6b  libogg-1.3.5.tar.gz
"
